package com.leetcodehot.problems;

public class problems2730 {
    public int longestSemiRepetitiveSubstring(String s) {
        char[] charArray = s.toCharArray();
        int n = charArray.length;
        if (n == 1) return 1;
        int left = 0;
        int res = 0;
        int count = 0;

        for (int right = 1; right < n; right++) {
            if (charArray[right] == charArray[right - 1]) {
                count++;
            }
            while (count > 1) {
                if (charArray[left] == charArray[left + 1]) {
                    count--;
                }
                left++;
            }
            res = Math.max(res, right - left + 1);
        }

        return res;
    }
}
